package com.example.my.shop.mybatis.controller;

import com.example.my.shop.mybatis.entity.TbUser;
import com.example.my.shop.mybatis.service.TbUserService;
import com.example.my.shop.mybatis.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/user_form_add")
public class User_form_addController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String passWord = req.getParameter("passWord");
        String phone = req.getParameter("phone");
        String email = req.getParameter("email");

        TbUserService tbUserService = new TbUserServiceImpl();
        TbUser tbUser = new TbUser(userName,passWord,phone,email);
        boolean b = tbUserService.addUser(tbUser);
        if(b) {
            req.setAttribute("message", "添加成功！！！");
        }else {
            req.setAttribute("message", "添加失败！！！");
        }
        req.getRequestDispatcher("/user_list").forward(req,resp);
    }
}
